home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’95 / Reminder Manager / DebugDisplay.c < prev    next >
C/C++ Source or Header  |  1995-06-24  |  3KB  |  102 lines

  1. #include <Quickdraw.h>
  2. #include "DebugDisplay.h"
  3. #define      NIL    0
  4.  
  5. extern char        ShowDebugFlag;    // are we showing our window
  6. extern long        starvation;        // how often we get execution cycles
  7. extern long        deltastarv;        // how much is it changing?
  8. extern long        dissatisfaction;// how often we get to play notes
  9.  
  10. static WindowPtr    DebugWindow;
  11.  
  12. void OpenDisplay(void)
  13. {
  14.     int         v,h;
  15.     WindowPtr   SavePort;
  16.     
  17.     if (ShowDebugFlag)
  18.     {
  19.         GetPort(&SavePort);
  20.         /*    3. Load the window */
  21.         DebugWindow = GetNewWindow(3,NIL, (WindowPtr)-1);
  22.         SetPort(DebugWindow);
  23.     
  24.         /*    4. resize the window */
  25.         HLock((Handle)DebugWindow);
  26.         SizeWindow(DebugWindow,280,80,TRUE);
  27.         
  28.         /*    5. Position the window top third center */
  29.         v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) 
  30.             - (DebugWindow->portRect.bottom - DebugWindow->portRect.top)) / 7;
  31.         h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) 
  32.             - (DebugWindow->portRect.right - DebugWindow->portRect.left)) / 5;
  33.         MoveWindow(DebugWindow,h,v,TRUE);
  34.         HUnlock((Handle)DebugWindow);
  35.         
  36.         /*    6. Show the window */        
  37.         ShowWindow(DebugWindow);
  38.         SetPort(SavePort);
  39.     }
  40. }
  41.  
  42. void DisposeDisplay(void)
  43. {
  44.     if (ShowDebugFlag)
  45.         if (DebugWindow!=NIL) {
  46.             DisposeWindow(DebugWindow); 
  47.             DebugWindow = NIL;
  48.         }
  49. }
  50.  
  51. void UpdateDisplay(void)
  52. {
  53.     WindowPtr   SavePort;
  54.     PicHandle   Pic_Handle;
  55.     Rect        grayRect1,grayRect2,
  56.                 whiteRect1,whiteRect2,whiteRect3,
  57.                 deltastarvrect,starvRect,stormRect;
  58.     SignedByte    huhstate;
  59.     
  60.     if (ShowDebugFlag)
  61.         if (DebugWindow!=NIL)
  62.         {
  63.             GetPort(&SavePort);
  64.             SetPort(DebugWindow);
  65.     
  66.             // the deltastarv line
  67.             if (deltastarv>0)
  68.                 SetRect(&deltastarvrect,25,24,(25+deltastarv),25);
  69.             if (deltastarv<10)    //if the delta is small, don't draw it.
  70.                 SetRect(&deltastarvrect,-10,-10,-10,-10);
  71.             if (deltastarv<0)
  72.                 SetRect(&deltastarvrect,(25+deltastarv),24,25,25);
  73.             // a white bar to overwrite the old one
  74.             SetRect(&whiteRect3,0,24,350,25);
  75.             // draw the damn thing
  76.             FillRect(&whiteRect3,&qd.white);
  77.             FillRect(&deltastarvrect,&qd.black);
  78.  
  79.             // the starv bar backgroundis gray, 
  80.             // then white to allow for "11"
  81.             SetRect(&grayRect1,25,25,255,35);
  82.             SetRect(&whiteRect1,255,25,350,35);
  83.             // and here's the dk gray value bar
  84.             SetRect(&starvRect,25,25,starvation+25,35);
  85.             // and draw it
  86.             FillRect(&grayRect1,&qd.ltGray);
  87.             FillRect(&whiteRect1,&qd.white);
  88.             FillRect(&starvRect,&qd.dkGray);
  89.  
  90.             // same story for the dissatisfaction bar
  91.             SetRect(&grayRect2,25,50,255,60);
  92.             SetRect(&whiteRect2,255,50,350,60);
  93.             // here's the value part
  94.             SetRect(&stormRect,25,50,dissatisfaction+25,60);
  95.             // drawing
  96.             FillRect(&grayRect2,&qd.ltGray);
  97.             FillRect(&whiteRect2,&qd.white);
  98.             FillRect(&stormRect,&qd.dkGray);
  99.     
  100.             SetPort(SavePort);
  101.         }
  102. }